import EventMgr from "../../../Core/Event/EventMgr";
import Log from "../../../Core/Log/Log";
import SdkTool from "../../../Core/Sdk/SdkTool";
import ProtoBufManager from "../../proto/ProtoBufManager";
import { common, lobby } from "../../proto/protoCmd";
import { ViewManager } from "../base/ViewManager";
import { AbstractModel } from "../socket/AbstractModel";
import { GameModels } from "../socket/GameModels";
import { ModelLobby } from "./ModelLobby";

export class ModelLogin extends AbstractModel {

    public send_ReqEnterLobby(): void {
        ViewManager.ins.showloading();
        const msg = ProtoBufManager.ins.lobby.ReqEnterLobby.create();
        msg.Uid = GameModels.info.playerInfo.UserId;
        msg.Token = SdkTool.ins.openid;
        const data = ProtoBufManager.ins.lobby.ReqEnterLobby.encode(msg).finish();
        this.send(1000, GameModels.info.playerInfo.LobbyRoute + `.ReqEnterLobby`, data);
    }
    protected registerInterestedProtocols(): void {
        this.reg(1000, this.onRespEnterLobby, `lobby`, `RespEnterLobby`);
        this.addRouteMap(`Lobby.Lobby.SyncUserBaseInfo`, this.onSyncUserBaseInfo, `lobby`, `SyncUserBaseInfo`);
    }
    private onSyncUserBaseInfo(info: lobby.SyncUserBaseInfo): void {
    }

    private onRespEnterLobby(info: lobby.RespEnterLobby): void {
        ViewManager.ins.removeLoading();
        GameModels.info.playerInfo.setinfo(info.BaseInfo);
        Log.ins.log(2, `进入游戏大厅成功,玩家uid:${info.BaseInfo.UserId},玩家昵称:${info.BaseInfo.NickName}`);
        GameModels.support.send_ReqGetItemBagList();
        EventMgr.emit(`event_RespEnterLobby`);

    }
}